﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CPPEI.PM.Shell.SysViews
{
    public partial class ContainerView 
    {
        [EventBus.Subscribe]
        public void OnReceiveUIOpenWorkSheetEvent(Event.UI.UIOpenWorkSheetEvent @event)
        {
            for (int index = 0; index < this._ctlTabPanel.Items.Count; index++)
            {
                Views.WorkSheetView view = _ctlTabPanel.Items[index] as Views.WorkSheetView;
                if (view.WorkSheetId == @event.WorkSheetId)
                {
                    this._ctlTabPanel.SelectedItem = view;
                    view.Refresh();
                    return;
                }


            }
            Views.WorkSheetView newView = new Views.WorkSheetView();
            int newIndex = this._ctlTabPanel.Items.Add(newView);
            this._ctlTabPanel.SelectedIndex = newIndex;

            newView.LoadWorkSheet(@event.WorkSheetId);
        }

        [EventBus.Subscribe]
        public void OnReceiveUIRefreshWorkSheetEvent(Event.UI.UIRefreshWorkSheetEvent @event)
        {
            this.Dispatcher.BeginInvoke(new Action(OnReceiveUIRefreshWorkSheetEventAction));
        }

        private void OnReceiveUIRefreshWorkSheetEventAction()
        {
            Views.WorkSheetView view = _ctlTabPanel.SelectedItem as Views.WorkSheetView;
            view.Refresh();
        }
    }
}
